<template>
  <view>
    <public-header title="优惠券信息"></public-header>
    <view class="retail-segmented bg-white" v-if="loaded">
      <uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="text"
        activeColor="#38C09E"></uni-segmented-control>
      <view class="content retail-segmented-content bg-white">
        <rList ref="rList0" :page="couponConfig.page" :config="couponConfig" style="height: 100%;" v-show="current===0">
        </rList>
        <rList ref="rList1" :page="config1.page" :config="config1" style="height: 100%;" v-show="current===1">
        </rList>
        <rList ref="rList2" :page="config2.page" :config="config2" style="height: 100%;" v-show="current===2">
        </rList>
      </view>
    </view>
  </view>
</template>

<script>
  import bUpdate from '@/components/g-batch-update/g-batch-update.vue'
  import rList from '@/components/retail-list/retail-list.vue'
  import lockscreen from '@/common/mixins/lockscreen.js'
  export default {
    mixins: [lockscreen],
    data() {
      return {
        items: ['优惠券信息', '领取记录', '核销记录'],
        current: 0,
        service: "", // 页面service
        type: "update", // 页面编辑模式
        couponConfig: {
          srv_app: "mkt",
          appName: 'mkt',
          hideGridButton: true,
          showRowButton: true,
          // serviceName: "srvmkt_coupon_manage_distributable_select",
          serviceName: "srvmkt_coupon_manage_select",
          listLayout: "listAndFilter", // listAndDetail listAndFilter  list  batchList   srvretail_stock_early_warning_select
          defaultData: "service-loading", // batch-select   service-loading
          detailPath: "simple", //  simple  基础的； 或者配置页面路由 路由格式待定
          page: {
            pageNo: 1,
            rownumber: 10
          },
          listHeaders: [''],
          childService: "srvmkt_coupon_manage_select",
          childKeyCol: "", // 子表数据的主键
          tabsType: "custom", //
          titleText: "返回",
          title: "",
          searchValKey: [],
          popupColumns: [],
          custTabs: [{
              "colName": "coupon_title",
              "type": "InputSelect",
              "inputType": "enum",
              "parent": "",
              "is_count": false,
              "show_expr": {},
              "label": "优惠券标题",
              "showLabel": true,
              "default": "",
              "colspan": 24,
              "showAllTag": false,
              "tags": []
            },
            {
              "colName": "coupon_type",
              "type": "Select",
              "inputType": "enum",
              "parent": "",
              "is_count": false,
              "show_expr": {},
              "label": "优惠券类型",
              "showLabel": true,
              "default": "",
              "colspan": 24,
              "showAllTag": false,
              "tags": []
            },
            {
              "colName": "display_state",
              "type": "Select",
              "inputType": "enum",
              "parent": "",
              "is_count": false,
              "show_expr": {},
              "label": "优惠券状态",
              "showLabel": true,
              "default": "",
              "colspan": 24,
              "showAllTag": false,
              "tags": [],
              "custom_options": [{
                  text: '已上架',
                  value: '已上架'
                },
                {
                  text: '已下架',
                  value: '已下架'
                },
                {
                  text: '已过期',
                  value: '已过期'
                }
              ],
              "appendSearchButton": true,
            }
          ],
          tabs: {
            layout: 'inline', // 'inline'   block
          }
        },
        config1: {
          srv_app: "mkt",
          appName: 'mkt',
          hideGridButton: true,
          showRowButton: false,
          serviceName: "srvmkt_member_coupon_select",
          listLayout: "listAndFilter", // listAndDetail listAndFilter  list  batchList   srvretail_stock_early_warning_select
          defaultData: "service-loading", // batch-select   service-loading
          detailPath: "simple", //  simple  基础的； 或者配置页面路由 路由格式待定
          page: {
            pageNo: 1,
            rownumber: 10
          },
          listHeaders: [''],
          childService: "srvmkt_member_coupon_select",
          childKeyCol: "", // 子表数据的主键
          tabsType: "custom", //
          titleText: "返回",
          title: "",
          searchValKey: [],
          popupColumns: [],
          custTabs: [{
              "colName": "coupon_title",
              "type": "InputSelect",
              "inputType": "enum",
              "parent": "",
              "is_count": false,
              "show_expr": {},
              "label": "优惠券标题",
              "showLabel": true,
              "default": "",
              "colspan": 24,
              "showAllTag": false,
              "tags": []
            },
            {
              "colName": "member_name,member_phone",
              "type": "input",
              "inputType": "String",
              "parent": "",
              "is_count": false,
              "show_expr": {},
              "label": "会员信息",
              "showLabel": true,
              "default": "",
              "colspan": 24,
              "showAllTag": false,
              "tags": []
            },
            {
              "colName": "coupon_type",
              "type": "Select",
              "inputType": "enum",
              "is_count": false,
              "show_expr": {},
              "label": "优惠券类型",
              "showLabel": true,
              "default": "",
              "colspan": 24,
              "showAllTag": false,
              "tags": []
            },
            {
              "colName": "receive_time",
              "type": "between",
              "inputType": "BetweenDate",
              "parent": "",
              "is_count": false,
              "show_expr": {},
              "label": "领取时间",

              "showLabel": true,
              "default": "",
              "colspan": 24,
              "showAllTag": false,
              "tags": [],
              "appendSearchButton": true,
            }
          ],
          tabs: {
            layout: 'inline', // 'inline'   block
          }

        },
        config2: {
          srv_app: "mkt",
          appName: 'mkt',
          hideGridButton: true,
          showRowButton: false,
          serviceName: "srvmkt_member_coupon_write_off_select",
          listLayout: "listAndFilter", // listAndDetail listAndFilter  list  batchList   srvretail_stock_early_warning_select
          defaultData: "service-loading", // batch-select   service-loading
          detailPath: "simple", //  simple  基础的； 或者配置页面路由 路由格式待定
          page: {
            pageNo: 1,
            rownumber: 10
          },
          listHeaders: [''],
          childService: "srvmkt_member_coupon_write_off_select",
          childKeyCol: "", // 子表数据的主键
          tabsType: "custom", //
          titleText: "返回",
          title: "",
          searchValKey: [],
          popupColumns: [],
          custTabs: [{
              "colName": "coupon_title",
              "type": "InputSelect",
              "inputType": "enum",
              "parent": "",
              "is_count": false,
              "show_expr": {},
              "label": "优惠券标题",
              "showLabel": true,
              "default": "",
              "colspan": 24,
              "showAllTag": false,
              "tags": []
            },
            {
              "colName": "member_name,member_phone",
              "type": "input",
              "inputType": "String",
              "parent": "",
              "is_count": false,
              "show_expr": {},
              "label": "会员信息",
              "showLabel": true,
              "default": "",
              "colspan": 24,
              "showAllTag": false,
              "tags": []
            },
            {
              "colName": "coupon_type",
              "type": "Select",
              "inputType": "enum",
              "is_count": false,
              "show_expr": {},
              "label": "优惠券类型",
              "showLabel": true,
              "default": "",
              "colspan": 24,
              "showAllTag": false,
              "tags": []
            },
            {
              "colName": "receive_time",
              "type": "between",
              "inputType": "BetweenDate",
              "parent": "",
              "is_count": false,
              "show_expr": {},
              "label": "核销时间",
              "showLabel": true,
              "default": "",
              "colspan": 24,
              "showAllTag": false,
              "tags": [],
              "appendSearchButton": true,
            }
          ],
          tabs: {
            layout: 'inline', // 'inline'   block
          }

        },
        condition: [],
        list: [],
        loaded:false,
        onHide:false
      };
    },
    components: {
      bUpdate,
      rList
    },
    created() {
      this.getAllCouponTitle()
    },
    onHide() {
      this.loaded = false
      this.onHide = true
    },
    onShow() {
      if(this.onHide===true){
        this.loaded = true
        this.onHide = false
      }
    },
    methods: {
      async getAllCouponTitle() {
        const url = `/mkt/select/srvmkt_coupon_manage_select`
        const req = {
          "serviceName": "srvmkt_coupon_manage_select",
          "colNames": ["*"],
          group: [{
            "colName": "coupon_title",
            "type": "by"
          }],
          condition:[{
            colName:'coupon_title',
            ruleType:'ne'
          }],
          "page": {
            "pageNo": 1,
            "rownumber": 999,
          }
        }
        const res = await this.$http.post(url, req)
        if (res.data?.state === 'SUCCESS') {
          this.config1.custTabs[0].custom_options = res.data.data.map(item => {
            return {
              label:item.coupon_title,
              text: item.coupon_title,
              value: item.coupon_title
            }
          })
          this.couponConfig.custTabs[0].custom_options = this.config1.custTabs[0].custom_options
          this.config2.custTabs[0].custom_options = this.config1.custTabs[0].custom_options
        }
        this.loaded = true
      },
      listLoad(e = []) {
        this.list = this.deepClone(e)
      },
      onGridButton(e) {
        console.log('onGridButton', e);
      },
      onItemChecked(e) {
        console.log('onItemChecked', e);
      },
      onClickItem(e) {
        console.log(e);
        // if (this.current != e.currentIndex) {
        this.current = e.currentIndex;
        this.$refs[`rList${this.current}`]?.getTableDatas()
        // }
      }
    }
  }
</script>

<style lang="scss" scoped>
  .retail-list .retail-list-right {
    height: calc(100vh-190rpx) !important;
  }
</style>
